package com.wutong.authority_server.security;

import com.wutong.authority_server.utils.MD5Utils;
import org.apache.commons.codec.digest.Md5Crypt;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

//自定义密码处理器
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder(){
        this(-1);
    }
    public DefaultPasswordEncoder(int strLength){

    }

    //密码md5加密
    @Override
    public String encode(CharSequence charSequence) {
        return MD5Utils.encrypt(charSequence.toString());
    }

    //密码比对
    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        return encodedPassword.equals(MD5Utils.encrypt(charSequence.toString()));
    }

    public static void main(String[] args) {
        System.out.println(MD5Utils.encrypt("1234"));
    }
}
